/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/

#pragma once

/*-----------------------------------------------------------------------------
	GL texture :
-----------------------------------------------------------------------------*/

class EGLBaseTexture : public ITexture {
	public:
						EGLBaseTexture	( void ) { gl_tex_obj = NULL; }
		virtual			~EGLBaseTexture	( void ) { glDeleteTextures(1, &gl_tex_obj); };
		virtual GLuint	GetTexObject	( void ) const { return gl_tex_obj; }
	protected:
		GLuint	gl_tex_obj;
	};


class EGLTexture : public EGLBaseTexture {
	public:
								EGLTexture		( void ) : width(0), height(0), depth(0), pitch(0), format(RS_FORMAT_UNKNOWN), type(RS_TEXTURE_UNKNOWN) { }
								~EGLTexture		( void );
		virtual uint			GetWidth		( void ) const { return width;		}
		virtual uint			GetHeight		( void ) const { return height;		}
		virtual uint			GetDepth		( void ) const { return depth;		}
		virtual ERSFormat_t		GetFormat		( void ) const { return format;		}
		virtual ERSTexType_t	GetType			( void ) const { return type;		}
		virtual bool			IsRenderTarget	( void ) const { return false;		}
		virtual void			WriteDataRaw2D	( uint level, const void *data, uint pitch );
		virtual void			UpdateFromImage	( const IPxImage image );

		virtual void			WriteDataRaw3D	( const float * data );
		
		
	static IPxTexture	CreateTextureFromFile	( const char *path );
	static IPxTexture	CreateTexture2D			( uint w, uint h, ERSFormat_t frmt );
	static IPxTexture	CreateTexture2D			( uint w, uint h, const EColor *data );
	static IPxTexture	CreateVolumeF4			( uint w, uint h, uint d, const EColor *float_data );
	static IPxTexture	CreateVolumeF			( uint w, uint h, uint d, const float  *float_data );
	static IPxTexture	CreateNullTexture		( void );
	static IPxTexture	CreateNoiseTexture		( void );
	static IPxTexture	CreateSolidTexture		( uchar r, uchar g, uchar b, uchar a );
	static IPxTexture	CreateColorTexture		( const char *path );
	static IPxTexture	CreateColormapTexture	( int n, const EColor *colors );

	static IPxTexture	LoadTextureFromImage	( const IPxImage image );
		
	protected:
		static IPxTexture	LoadTextureFromFile		( const char *path );
		//static IPxTexture	LoadTextureFromImage	( const IPxImage image );
		
		void				CreateGLTexture1D		( GLenum target, GLint internalformat, GLenum format, GLenum type, const GLvoid *pixels );
		void				CreateGLTexture2D		( GLenum target, GLint internalformat, GLenum format, GLenum type, const GLvoid *pixels );
		void				CreateGLTexture3D		( GLenum target, GLint internalformat, GLenum format, GLenum type, const GLvoid *pixels );
	
		uint	width;
		uint	height;
		uint	depth;
		uint	pitch;

		ERSFormat_t		format;
		ERSTexType_t	type;
	};
	